package org.jeecgframework.test.demo;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jeecgframework.AbstractUnitTest;
import org.jeecgframework.core.common.dao.impl.CommonDao;
import org.jeecgframework.web.system.pojo.base.TSUser;
import org.jeecgframework.web.system.service.SystemService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
/**
 * DAO 测试DEMO
 * @author 许国杰
 *
 */
public class DaoTestDemo extends AbstractUnitTest{
	@Autowired
	private CommonDao commonDao ;
	@Autowired
	private SystemService systemService;
	
	@Test
	public void testGetUserRole() {
		
		StringBuffer sb = new StringBuffer();
		
		
		//sb.append("SELECT DATE_FORMAT(createDate,'%Y%m%d')  as createDate  ,count(*) FROM EduEarlyIndustryEntity WHERE  FIND_IN_SET ('02',onLine)   group by DATE_FORMAT(createDate,'%Y%m%d')  ORDER BY DATE_FORMAT(createDate,'%Y%m%d') ASC");
		//List userBroswerList = systemService.findByQueryString(sb.toString());
		String query = " SELECT DATE_FORMAT( a.`create_date`,'%Y%m%d') days ,COUNT(*) AS 'count' FROM edu_early_industry a WHERE  FIND_IN_SET ('02',a.`on_line`)  GROUP BY  DATE_FORMAT( a.`create_date`,'%Y%m%d')  ORDER BY DATE_FORMAT( a.`create_date`,'%Y%m%d') ASC ";
		List userBroswerList =systemService.findListbySql(query);
	    System.out.println("userBroswerList=== "+userBroswerList.size());

	}
	
	
	@Test
	public void testStr(){
		int[] days = {20170701,20170702,20170703,20170704,20170705,20170706,20170707};
		List lt = new ArrayList();
		
		Map<String, Object>  map1 = new HashMap<String, Object>();
		map1.put("name", 20170702);
		map1.put("y", 4);
		map1.put("percentage", 0);
		
		
		Map<String, Object> map2 = new HashMap<String, Object>();
		map2.put("name", 20170714);
		map2.put("y", 10);
		map2.put("percentage", 0);
		
		lt.add(map1);
		lt.add(map2);
		
		
		
		Map<String, Object> map;
		
		for(int i=0;i<days.length ;i++){
			boolean flags=false;
			for(int j=0;i<lt.size();j++){
				Map<String, Object> obj =(Map<String, Object>) lt.get(j);
				if(obj.get("name").equals(days[i])){							
					flags=true;
					break;
				}					
			}
			if(!flags){
				map = new HashMap<String, Object>();
				map.put("name", days[i]);
				map.put("y", 0);
				map.put("percentage", 0);
			   lt.add(map); 
			}
		}		
		
	}
	

}
